﻿package mortal.game.view.guildNew.info
{
    import extend.language.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.guildNew.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.guildNew.info.data.*;
    import mortal.game.view.guildNew.manor.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewInfoProcessor extends Object
    {
        private var _view:IView;

        public function GuildNewInfoProcessor()
        {
            this.initServer();
            return;
        }// end function

        public function initView(param1:IView) : void
        {
            this._view = param1;
            return;
        }// end function

        public function initServer() : void
        {
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewInfoOper, this.onBtnCk, true);
            EventUtil.addSelfEvent(EventName.GUILD_PURPOSE_CHANGE, this.changeGuildPurpose, true);
            EventUtil.addSelfEvent(EventName.GuildDonateResource, this.donateResourceRequest, true);
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewInfoChangeName, this.changeGuildNameRequest, true);
            EventUtil.addSelfEvent(EventName.GuildNewChangeNameSuccess, this.changeNameSuccess, true);
            return;
        }// end function

        public function onViewShow() : void
        {
            this.addEvs(true);
            return;
        }// end function

        public function onViewHide() : void
        {
            if (GuildAppointPanel.hasInstance && !GuildAppointPanel.instance.isHide)
            {
                GuildAppointPanel.instance.hide();
            }
            this.addEvs(false);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(EventName.GuildNewChangeNameSuccess, this.changeNameSuccess, param1);
            return;
        }// end function

        private function onBtnCk(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            if (_loc_2 == null || _loc_2.hasOwnProperty("oper") == false)
            {
                return;
            }
            switch(_loc_2.oper)
            {
                case GNInfoOprType.Mort:
                {
                    GuildPositonIntroducePanel.instance.popUp();
                    break;
                }
                case GNInfoOprType.Mem:
                {
                    Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.ModuleChangeTab, GuildNewModule.Member));
                    break;
                }
                case GNInfoOprType.Rank:
                {
                    if (this._view && this._view.isHide == false)
                    {
                        (this._view as GuildNewModule).selectedIndex = GuildNewModule.Manor;
                        this.selectMyGuildRank();
                    }
                    break;
                }
                case GNInfoOprType.Adont:
                {
                    GuildDonateResource.instance.popUp();
                    break;
                }
                case GNInfoOprType.Copy:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDefenseWinOpen));
                    break;
                }
                case GNInfoOprType.BOSS:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildActivityShow));
                    break;
                }
                case GNInfoOprType.Diner:
                {
                    GameController.copy.winePartyCopy.view.show();
                    break;
                }
                case GNInfoOprType.Mission:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildTaskDoubleRewardViewShow, true));
                    break;
                }
                case GNInfoOprType.Gift:
                {
                    GameProxy.guild.getDayReward();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function changeGuildPurpose(event:DataEvent) : void
        {
            var _loc_2:* = String(event.data);
            if (_loc_2.length > GuildConst.MaxPurposeLength)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71479));
                return;
            }
            GameProxy.guild.changeGuildPurpose(_loc_2);
            return;
        }// end function

        private function donateResourceRequest(event:DataEvent) : void
        {
            GameProxy.guild.donateResource(event.data.item, event.data.money);
            return;
        }// end function

        private function selectMyGuildRank() : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_1:* = (this._view as GuildNewModule).curPanel as GuildNewManorPanel;
            if (_loc_1)
            {
                _loc_1.onTextLink(null);
            }
            return;
        }// end function

        private function changeGuildNameRequest(event:DataEvent) : void
        {
            var _loc_2:* = event.data as String;
            GameProxy.guild.changeGuildName(_loc_2);
            return;
        }// end function

        private function changeNameSuccess(event:DataEvent) : void
        {
            GuildNewInfoChangeName.instance.hide();
            MsgManager.showRollTipsMsg("" + Language.getString(71699));
            return;
        }// end function

    }
}
